Skip to content

Scaffolding rollout workspace multi worker#1011

Closed
narutolhy wants to merge 18 commits into
areal-project:mainfrom
WeiHaocheng:scaffolding_rollout_workspace_multi_worker
Closed

Scaffolding rollout workspace multi worker#1011
narutolhy wants to merge 18 commits into
areal-project:mainfrom
WeiHaocheng:scaffolding_rollout_workspace_multi_worker

Conversation

@narutolhy

Copy link
Copy Markdown

Description

Related Issue

Fixes #(issue)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not
    work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Checklist

  • I have read the Contributing Guide
  • I have run formatting tools (pre-commit or manual)
  • I have run relevant unit tests and they pass
  • I have added tests for new functionality
  • I have updated documentation if needed
  • My branch is up to date with main
  • This PR introduces breaking changes (if yes, fill out details below)
  • If this PR changes documentation, I have built and previewed it locally with
    jb build docs
  • No critical issues raised by AI reviewers (/gemini review)

Breaking Change Details (if applicable):

Additional Context


Need help? Check the Contributing Guide or ask in
GitHub Discussions!

WeiHaocheng and others added 18 commits February 16, 2026 10:42
init scaffolding

init scaffolding

run gsm8k

fix workflow

no skip tokenizer

fix reward multi-thread and oom
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add is_ipv6_address() to detect IPv6 address strings
- Add format_addr() to bracket IPv6 in host:port strings (RFC 2732)
- Extend gethostip() with IPv6 fallback for IPv6-only environments
- Update is_port_free() to check both AF_INET and AF_INET6

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use format_addr() everywhere host:port strings are constructed so that
IPv6 addresses are properly bracketed in URLs. Also:
- remote_inf_engine: accept per-worker port_range to avoid concurrent
  find_free_ports() TOCTOU races when multiple workers start in parallel
- rollout_controller: partition port space by worker rank so each worker
  picks from a non-overlapping range, eliminating bind conflicts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Bracket IPv6 addresses in tcp://[addr]:port init_method so PyTorch
  dist.init_process_group can parse the URL correctly
- Pass group=self.cpu_group (Gloo) to allocate_balanced_mbs_synced
  inside split_padded_tensor_dict_into_mb_list; without this it falls
  back to NCCL WORLD which hangs on nodes where IB has no routing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When multiple arun_episode coroutines run concurrently they previously
shared mutable state on PipelineTrajectoryMaker (task_data, prompt_str,
input_tokens), causing later episodes to overwrite earlier ones before
generation completed.

- ScaffoldingLlm.generate_async: clone prototype_controller synchronously
  before any async handoff so each episode gets its own isolated clone
- ScaffoldingWorkflow.arun_episode: pass per-episode data as kwargs to
  generate_async instead of mutating shared trajectory_maker fields
- PipelineTrajectoryMaker.process: pop task_data/prompt_str/input_tokens
  from kwargs so each cloned controller sees its own episode data

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GSM8KScaffoldingWorkflow.build_scaffolding_llm was constructing
NativeGenerationController() with no arguments, leaving sampling_params
empty. convert_task_params skips None fields, so SGLang never received
max_tokens and defaulted to ~16 tokens, producing truncated completions
and near-zero rewards (~0.3%).

Fix: delegate to super().build_scaffolding_llm(engine) which correctly
builds sampling_params from gconfig (max_tokens, temperature, stop).

Also clean up debug instrumentation added during investigation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- cli_args: raise setup_timeout 300→1200s (SGLang model loading on large
  clusters takes >5 min); add sdpa/eager to attn_impl choices; use
  sys.executable instead of hardcoded python3
- ray.py: raise startup_timeout 30→600s for multi-node Ray worker join
- gsm8k dataset: update prompt to request step-by-step reasoning
- chat_scaffolding.yaml: update to 8-GPU xccl config
- Add gsm8k_rlvr_scaffolding_2nodes.yaml for 2-node A100 Ray setup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands AReaL's capabilities by integrating a flexible Scaffolding framework, allowing for more sophisticated and composable reinforcement learning workflows. It enhances the system's ability to manage multi-worker inference and training, particularly for large language models, through improved networking and dynamic resource allocation. The changes lay the groundwork for advanced RL techniques like verifiable rewards and multi-turn conversational agents, making the platform more versatile and robust for complex AI research.

Highlights

  • Scaffolding Framework Integration: Introduced a comprehensive Scaffolding framework, vendored from TensorRT-LLM, to enable modular composition of inference-time compute methods with AReaL's RL training pipeline. This includes new Controller, Worker, Task, and ScaffoldingLlm primitives.
  • Multi-Worker and Networking Enhancements: Implemented robust multi-worker support with dynamic port allocation and improved IPv6 compatibility across various components, including the FSDP engine, SGLang server, and RPC communication, to prevent port conflicts and ensure broader network compatibility.
  • RLVR and Chat Workflow Support: Added AReaL-specific scaffolding components such as RLVRRewardController for verifiable reward computation, PipelineTrajectoryMaker for composing generation and reward pipelines, and ChatTracer and MultiTurnChatController for multi-turn chat with reflection, facilitating advanced RL workflows.
  • Improved Robustness and Configuration: Increased the default setup timeout for inference engines and refined the MathVerifyWorker to use direct parsing and verification, disabling signal-based timeouts to enhance stability in multi-threaded environments.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • areal/api/cli_args.py
    • Added sys import for system-level executable path resolution.
    • Expanded TrainEngineConfig's attn_impl choices to include 'sdpa' and 'eager' for broader attention mechanism support.
    • Updated get_py_cmd to use sys.executable for more portable Python command execution.
    • Increased InferenceEngineConfig's setup_timeout default to 1200.0 seconds for longer server connection/launch times.
  • areal/dataset/gsm8k.py
    • Modified the GSM8K dataset prompt to encourage step-by-step reasoning and numeric answers, replacing the 'boxed' format.
  • areal/engine/fsdp_engine.py
    • Imported format_addr and is_ipv6_address for enhanced network address handling.
    • Modified weight update initialization and broadcast methods to correctly format and handle IPv6 master addresses.
    • Updated _prepare_mb_list to pass group=self.cpu_group during micro-batch splitting, improving CPU group awareness.
  • areal/experimental/openai/cache.py
    • Implemented a __deepcopy__ method for InteractionCache to ensure fresh, empty caches are created during deep copies, avoiding issues with uncopyable threading.Lock objects.
  • areal/experimental/scaffolding/init.py
    • Added a new module to define and re-export key components of the Scaffolding Framework Integration for AReaL.
  • areal/experimental/scaffolding/_compat.py
    • Added a new module to re-export core scaffolding classes from the vendored TensorRT-LLM primitives, simplifying imports within AReaL.
  • areal/experimental/scaffolding/controllers.py
    • Added a new module introducing RLVRRewardController for verifiable reward computation, ChatTracer for multi-turn chat tracing, PipelineTrajectoryMaker for composing generation and reward pipelines, and MultiTurnChatController for multi-turn chat with reflection.
  • areal/experimental/scaffolding/core/init.py
    • Added a new module vendoring and re-exporting core scaffolding primitives from TensorRT-LLM.
  • areal/experimental/scaffolding/core/controller.py
    • Added a new module defining the base Controller class and various concrete controllers for generation, chat, reward, majority voting, and best-of-N strategies.
  • areal/experimental/scaffolding/core/math_utils.py
    • Added a new module providing utility functions for extracting answers from text (e.g., \boxed{} expressions) and performing majority voting.
  • areal/experimental/scaffolding/core/result.py
    • Added a new module defining ScaffoldingOutput and ScaffoldingResult for handling outputs and asynchronous streaming in the scaffolding framework.
  • areal/experimental/scaffolding/core/scaffolding_llm.py
    • Added a new module implementing ScaffoldingLlm, the central orchestrator for managing asynchronous requests between controllers and workers.
  • areal/experimental/scaffolding/core/task.py
    • Added a new module defining base Task classes and specialized tasks for generation, streaming, rewards, and chat messages (e.g., UserMessage, AssistantMessage).
  • areal/experimental/scaffolding/core/task_collection.py
    • Added a new module defining TaskCollection for lifecycle hooks and decorators, along with token counters and metrics collectors.
  • areal/experimental/scaffolding/core/worker.py
    • Added a new module defining the base Worker class and an OpenaiWorker for handling tasks, including deterministic mode checks.
  • areal/experimental/scaffolding/task.py
    • Added a new module defining AReaL-specific scaffolding tasks: RLVRRewardTask for verifiable rewards, TraceGenerationTask for tracing, and ChatRewardTask for chat-specific reward computation.
  • areal/experimental/scaffolding/worker.py
    • Added a new module implementing SGLangWorker to wrap AReaL's SGLang engine for scaffolding, and CreateWorkerFromEngine for worker instantiation.
  • areal/experimental/scaffolding/workflow.py
    • Added a new module implementing ScaffoldingWorkflow, a RolloutWorkflow integration that leverages scaffolding components for generation and reward computation.
  • areal/infra/controller/rollout_controller.py
    • Updated _async_initialize to use format_addr for engine addresses, ensuring correct IPv6 formatting.
    • Modified server launch logic to assign unique port ranges to workers, preventing port conflicts in multi-worker setups.
    • Updated _async_start_proxy and callback_addr to use format_addr for consistent address formatting.
  • areal/infra/launcher/sglang_server.py
    • Imported format_addr for consistent network address formatting.
    • Updated server address generation and name resolution to use format_addr.
  • areal/infra/remote_inf_engine.py
    • Imported format_addr and is_ipv6_address for improved network utility.
    • Updated addresses to use format_addr for consistent formatting.
    • Modified launch_server to support IPv6 bind addresses and dynamic port range allocation for local inference servers.
    • Updated _shutdown_one_server to use format_addr for address consistency.
  • areal/infra/rpc/rpc_server.py
    • Imported format_addr for consistent network address formatting.
    • Updated _wait_for_worker_ready to use format_addr for health check URLs.
  • areal/infra/scheduler/ray.py
    • Increased RayScheduler's startup_timeout default from 30.0 to 600.0 seconds for more robust startup in complex environments.
  • areal/reward/init.py
    • Updated math_verify imports to use grader.verify and parser.parse directly.
    • Refactored MathVerifyWorker to use direct parsing and verification, disabling signal-based timeouts to improve compatibility in multi-threaded contexts.
  • areal/tests/experimental/scaffolding/test_controllers.py
    • Added a new file containing unit tests for the scaffolding controllers, including TraceTrajectoryMaker, PipelineTrajectoryMaker, and RLVRRewardController.
  • areal/tests/experimental/scaffolding/test_scaffolding_llm_integration.py
    • Added a new file containing integration tests for ScaffoldingLlm with various controller pipelines, covering synchronous, asynchronous, and concurrent execution scenarios.
  • areal/tests/experimental/scaffolding/test_worker.py
    • Added a new file containing tests for SGLangWorker functionality, including generation and chat handling with a real SGLang server.
  • areal/tests/experimental/scaffolding_core/test_self_contained.py
    • Added a new file containing tests to verify that the vendored scaffolding modules are self-contained and do not introduce external dependencies like tensorrt_llm.
  • areal/utils/network.py
    • Added is_ipv6_address and format_addr utility functions for robust IPv6 handling.
    • Modified gethostip to include IPv6 fallback, ensuring broader network compatibility.
    • Updated is_port_free to check port availability across both IPv4 and IPv6 address families.
  • examples/scaffolding/README.md
    • Added a new README file providing an overview, architecture, and usage examples for the Scaffolding Framework in AReaL.
  • examples/scaffolding/chat_scaffolding.py
    • Added a new example script demonstrating multi-turn chat-based RL training on GSM8K using the new scaffolding framework.
  • examples/scaffolding/chat_scaffolding.yaml
    • Added a new configuration file for the multi-turn chat scaffolding example.
  • examples/scaffolding/gsm8k_rlvr_scaffolding.py
    • Added a new example script for RLVR training on GSM8K using the scaffolding framework.
  • examples/scaffolding/gsm8k_rlvr_scaffolding.yaml
    • Added a new configuration file for the RLVR scaffolding example.
  • examples/scaffolding/gsm8k_rlvr_scaffolding_2nodes.yaml
    • Added a new configuration file for a multi-node RLVR scaffolding example.
Activity
  • The pull request introduces a significant new feature: the Scaffolding framework, which integrates advanced inference and reward computation into AReaL's RL training pipeline.
  • The author, narutolhy, has provided a detailed description outlining the purpose, key components, and related issues, indicating a well-planned and substantial contribution.
  • The changes involve adding numerous new files and modifying existing core components to support the new framework, suggesting a comprehensive implementation effort.
  • Extensive test files have been added, including unit and integration tests, to ensure the correctness and robustness of the new scaffolding components and their interaction with AReaL's infrastructure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant new feature: the scaffolding framework for composing inference and training workflows. The implementation is robust, featuring a well-designed asynchronous architecture to prevent deadlocks, and includes comprehensive improvements for multi-worker and IPv6 environments. The code is well-structured, extensively tested with both unit and integration tests, and includes clear examples. I have reviewed the changes and found no issues of medium or higher severity; the quality of the implementation is excellent.

Note: Security Review did not run due to the size of the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants